package study.ai.langchain4j.controller;

import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import study.ai.langchain4j.service.ChatAssistant;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/rag")
public class RagController {

    private String path = "D:\\idea_workspace\\study\\ai\\study-ai-langchain4j\\doc\\file";

    @Autowired
    private EmbeddingStore embeddingStore;
    @Autowired
    private ChatAssistant chatAssistant;

    @RequestMapping("/load")
    public String load() {
        List<Document> docs = FileSystemDocumentLoader.loadDocuments(path);
        EmbeddingStoreIngestor.ingest(docs, embeddingStore);
        return "success";
    }

    @RequestMapping("/chat/high")
    public String high(@RequestParam("message") String message) {
        return chatAssistant.chat(message);
    }
}
